<html>
<head><meta charset="utf-8"><title>simd in const fn #64738 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html">simd in const fn #64738</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="176540753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540753">(Sep 25 2019 at 07:40)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> so i'm not 100% sure that miri is the right place for the const fn intrinsics</p>



<a name="176540775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540775">(Sep 25 2019 at 07:40)</a>:</h4>
<p>I actually started implementing it there, but the "intrinsics" being matched there are more like FFI calls and such</p>



<a name="176540807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540807">(Sep 25 2019 at 07:41)</a>:</h4>
<p>yes, just like in codegen</p>



<a name="176540814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540814">(Sep 25 2019 at 07:41)</a>:</h4>
<p>miri is more like codegen and less like const eval</p>



<a name="176540819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540819">(Sep 25 2019 at 07:41)</a>:</h4>
<p>yeah</p>



<a name="176540828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540828">(Sep 25 2019 at 07:41)</a>:</h4>
<p>what I'm saying is that you can literally run your normal code using those intrinsics in miri</p>



<a name="176540831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540831">(Sep 25 2019 at 07:41)</a>:</h4>
<p>so right now the simd intrinsics are quite tied to the llvm codegen backend</p>



<a name="176540843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540843">(Sep 25 2019 at 07:41)</a>:</h4>
<p>yes, but IIUC that would also work by putting them in const eval right ?</p>



<a name="176540846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540846">(Sep 25 2019 at 07:41)</a>:</h4>
<p>and once all that works nicely (you'll be iterating faster on miri than on rustc), we can move to rustc</p>



<a name="176540890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540890">(Sep 25 2019 at 07:42)</a>:</h4>
<p>I see</p>



<a name="176540919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540919">(Sep 25 2019 at 07:42)</a>:</h4>
<p>yes, but we don't put things in const eval that aren't RFCed unless there's a very good reason</p>



<a name="176540926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540926">(Sep 25 2019 at 07:42)</a>:</h4>
<p>so, maybe we could FCP these ?</p>



<a name="176540930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540930">(Sep 25 2019 at 07:42)</a>:</h4>
<p>in miri we'll be much more lenient with hacks and stuff</p>



<a name="176540938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540938">(Sep 25 2019 at 07:42)</a>:</h4>
<p>I mean we want to support these properly at some point</p>



<a name="176540943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540943">(Sep 25 2019 at 07:42)</a>:</h4>
<p>IIRC we already handle simd_shuffles somewhere in there for some reason</p>



<a name="176540952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540952">(Sep 25 2019 at 07:43)</a>:</h4>
<p>sure, but you can't really test them without higher level changes</p>



<a name="176540953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540953">(Sep 25 2019 at 07:43)</a>:</h4>
<p>(or at least I've seen simd_shuffle in the const eval code)</p>



<a name="176540956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540956">(Sep 25 2019 at 07:43)</a>:</h4>
<p>that's not in const eval</p>



<a name="176540959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540959">(Sep 25 2019 at 07:43)</a>:</h4>
<p>we const eval the simd shuffle args</p>



<a name="176540961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540961">(Sep 25 2019 at 07:43)</a>:</h4>
<p>that's different</p>



<a name="176540964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540964">(Sep 25 2019 at 07:43)</a>:</h4>
<p>ah, yes that makes sense, they must be constant</p>



<a name="176540971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176540971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176540971">(Sep 25 2019 at 07:44)</a>:</h4>
<p>so the reason I don't want this in const eval is because I hate the test that you added. Not because of the content, but because of the unleash and other errors</p>



<a name="176541012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541012">(Sep 25 2019 at 07:44)</a>:</h4>
<p>yes</p>



<a name="176541014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541014">(Sep 25 2019 at 07:44)</a>:</h4>
<p>it is really hard to differentiate between actual hacks and incomplete or broken things</p>



<a name="176541016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541016">(Sep 25 2019 at 07:44)</a>:</h4>
<p>in miri you can do this cleanly</p>



<a name="176541017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541017">(Sep 25 2019 at 07:44)</a>:</h4>
<p>no hacks needed</p>



<a name="176541018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541018">(Sep 25 2019 at 07:44)</a>:</h4>
<p>no intermingling with const fn</p>



<a name="176541021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541021">(Sep 25 2019 at 07:44)</a>:</h4>
<p>wait, can't we just say that these intrinsics are const fn ?</p>



<a name="176541029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541029">(Sep 25 2019 at 07:44)</a>:</h4>
<p>like when doing <code>extern "platform-intrinsics" { ... }</code></p>



<a name="176541038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541038">(Sep 25 2019 at 07:45)</a>:</h4>
<p>You are using the word "just" just like I'm using it often and I don't think it means what we use it for</p>



<a name="176541039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541039">(Sep 25 2019 at 07:45)</a>:</h4>
<p>can I just say <code>const fn simd_insert</code> ?</p>



<a name="176541047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541047">(Sep 25 2019 at 07:45)</a>:</h4>
<p>and no that doesn't work ;)</p>



<a name="176541050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541050">(Sep 25 2019 at 07:45)</a>:</h4>
<p>so what would be required to test these without unleash ?</p>



<a name="176541104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541104">(Sep 25 2019 at 07:46)</a>:</h4>
<p>I mean, I think what I want is to make these true const fns</p>



<a name="176541111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541111">(Sep 25 2019 at 07:46)</a>:</h4>
<p>you need to add them to the big list of const evaluable intrinsics, grep for "size_of" (including quotes), there aren't that many uses of it and one of them is the list</p>



<a name="176541124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541124">(Sep 25 2019 at 07:46)</a>:</h4>
<p>ok, yea, we could add them to the list</p>



<a name="176541125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541125">(Sep 25 2019 at 07:46)</a>:</h4>
<p>ah, yes, I think I've seen that list (I added the <code>is_const_eval</code> thingy there by mistake)</p>



<a name="176541141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541141">(Sep 25 2019 at 07:47)</a>:</h4>
<p>so looking at all the simd intrinsics that we have</p>



<a name="176541144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541144">(Sep 25 2019 at 07:47)</a>:</h4>
<p>I think that most of them can be added to the list</p>



<a name="176541151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541151">(Sep 25 2019 at 07:47)</a>:</h4>
<p>see <a href="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L9" target="_blank" title="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L9">https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L9</a> for the list</p>



<a name="176541161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541161">(Sep 25 2019 at 07:47)</a>:</h4>
<p>kind of overlapping with <a href="https://github.com/rust-lang/rust/pull/61835" target="_blank" title="https://github.com/rust-lang/rust/pull/61835">https://github.com/rust-lang/rust/pull/61835</a> but that should be manageable</p>



<a name="176541162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541162">(Sep 25 2019 at 07:47)</a>:</h4>
<p>and there: <a href="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51" target="_blank" title="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51">https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51</a></p>



<a name="176541216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541216">(Sep 25 2019 at 07:48)</a>:</h4>
<p>most of them are just "add", "eq", etc.</p>



<a name="176541219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541219">(Sep 25 2019 at 07:48)</a>:</h4>
<p>there are some tricky ones though, e.g., simd_select does a branch, but both arguments are always evaluated</p>



<a name="176541221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541221">(Sep 25 2019 at 07:48)</a>:</h4>
<p>I so want these to have const generics &lt;/offtopic&gt;</p>



<a name="176541228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541228">(Sep 25 2019 at 07:49)</a>:</h4>
<p>yes that would improve their API</p>



<a name="176541234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541234">(Sep 25 2019 at 07:49)</a>:</h4>
<p>the plan is not to expose any of these</p>



<a name="176541248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541248">(Sep 25 2019 at 07:49)</a>:</h4>
<p>so in miri you only need one impl for all of these</p>



<a name="176541249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541249">(Sep 25 2019 at 07:49)</a>:</h4>
<p>but to use them internally in core to implement normal Rust wrappers that expose the functionality in a stable way</p>



<a name="176541251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541251">(Sep 25 2019 at 07:49)</a>:</h4>
<p>because you can extract the index from the name ;)</p>



<a name="176541261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541261">(Sep 25 2019 at 07:49)</a>:</h4>
<p>you mean the shuffles ?</p>



<a name="176541274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541274">(Sep 25 2019 at 07:50)</a>:</h4>
<p>I think we should refactor them in the llvm_codegen_backend at some point anyways</p>



<a name="176541278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541278">(Sep 25 2019 at 07:50)</a>:</h4>
<p>yes</p>



<a name="176541331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541331">(Sep 25 2019 at 07:50)</a>:</h4>
<p>the way it is currently done isn't great</p>



<a name="176541381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541381">(Sep 25 2019 at 07:51)</a>:</h4>
<p>I think we can probably just make the array a generic parameter</p>



<a name="176541384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541384">(Sep 25 2019 at 07:51)</a>:</h4>
<p>even without const generics</p>



<a name="176541390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541390">(Sep 25 2019 at 07:51)</a>:</h4>
<p>heh or that</p>



<a name="176541395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541395">(Sep 25 2019 at 07:51)</a>:</h4>
<p>but nobody has bothered</p>



<a name="176541397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541397">(Sep 25 2019 at 07:51)</a>:</h4>
<p>ok, so I'd be fine with unstably adding these intrinsics just like in your PR, as long as the tests don't need unleash, but just a feature gate</p>



<a name="176541447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541447">(Sep 25 2019 at 07:52)</a>:</h4>
<p>so appart from simd_select, then there are also scatter and gather: <a href="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L97" target="_blank" title="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L97">https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L97</a></p>



<a name="176541449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541449">(Sep 25 2019 at 07:52)</a>:</h4>
<p>well... I don't want to see 5 impls of the same intrinsic in const eval :P whatever solves that is fine with me for now</p>



<a name="176541454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541454">(Sep 25 2019 at 07:52)</a>:</h4>
<p>these take a vector of pointers, and dereferences them</p>



<a name="176541494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541494">(Sep 25 2019 at 07:53)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> I suppose i can match <code>s.starts_with("simd_shuffle")</code> and save some boilerplate</p>



<a name="176541502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541502">(Sep 25 2019 at 07:53)</a>:</h4>
<p>oh matching on all names is fine</p>



<a name="176541505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541505">(Sep 25 2019 at 07:53)</a>:</h4>
<p>as long as the code is just one arm</p>



<a name="176541552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541552">(Sep 25 2019 at 07:54)</a>:</h4>
<p>for the vector of pointers, I don't know if need extra care, like gating that on a feature gate or something</p>



<a name="176541556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541556">(Sep 25 2019 at 07:54)</a>:</h4>
<p>there was a gate for pointers in const fn, so it might make sense to reuse that</p>



<a name="176541575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176541575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176541575">(Sep 25 2019 at 07:55)</a>:</h4>
<p>these are all going to be scalarized internally, so since the operations for pointer dereference are already feature-gated, then this might not be necessary</p>



<a name="176543793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176543793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176543793">(Sep 25 2019 at 08:29)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> so I've pushed a commit that removes the need for -Zunleash</p>



<a name="176543819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176543819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176543819">(Sep 25 2019 at 08:29)</a>:</h4>
<p>other than that, could you let me know if that PR uses Operand/OpTy/MPlace/Place/... correctly ?</p>



<a name="176543899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176543899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176543899">(Sep 25 2019 at 08:30)</a>:</h4>
<p>I'm not sure when should I prefer MPlaceTy vs PlaceTy, or Immediate vs ImmTy, or whether the way in which I read an Abi::Vector into a Vec&lt;ImmTy&gt; is the right way to do that</p>



<a name="176543920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176543920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176543920">(Sep 25 2019 at 08:31)</a>:</h4>
<p>I'd rather understand those well before sending PRs for the remaining intrinsics</p>



<a name="176544653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176544653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176544653">(Sep 25 2019 at 08:41)</a>:</h4>
<p>yes, looks generally alright from the way you use operand, place and mplace</p>



<a name="176544666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176544666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176544666">(Sep 25 2019 at 08:41)</a>:</h4>
<p>I left a comment for a refactoring</p>



<a name="176545814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176545814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176545814">(Sep 25 2019 at 08:59)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> by assert you mean to use <code>bug!</code> right?</p>



<a name="176546787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176546787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176546787">(Sep 25 2019 at 09:14)</a>:</h4>
<p>there's an <code>if</code>, you can just assert the condition instead of <code>bug!</code>ing in the <code>else</code></p>



<a name="176549169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549169">(Sep 25 2019 at 09:49)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> looking at the other simd intrinsics</p>



<a name="176549198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549198">(Sep 25 2019 at 09:50)</a>:</h4>
<p>i wonder why there are so many binary_op_ methods</p>



<a name="176549252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549252">(Sep 25 2019 at 09:50)</a>:</h4>
<p>and why the "general" one does not handle all cases</p>



<a name="176549288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549288">(Sep 25 2019 at 09:50)</a>:</h4>
<p>e.g. we have <code>BinOp::Add</code>, so we need many <code>binary_op_</code> methods to handle wrapping, saturating, overflowing, etc. add</p>



<a name="176549305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549305">(Sep 25 2019 at 09:51)</a>:</h4>
<p>why not have <code>BinOp::WrappingAdd</code>, <code>BinOp::SaturatingAdd</code>, <code>BinOp::OverflowingAdd</code>, etc. instead ?</p>



<a name="176549414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549414">(Sep 25 2019 at 09:52)</a>:</h4>
<p>the reason is that the general one is equivalent to <code>checked_*</code> and the others are just essentially wrappers around the <code>checked_*</code> op</p>



<a name="176549431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549431">(Sep 25 2019 at 09:53)</a>:</h4>
<p>basically for code deduplication</p>



<a name="176549643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549643">(Sep 25 2019 at 09:55)</a>:</h4>
<p>But can't that happen inside a generic <code>binary_op</code> function ?</p>



<a name="176549720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549720">(Sep 25 2019 at 09:56)</a>:</h4>
<p>For SIMD types, I'd like to just loop over the elements, call binary_op, and then do some result handling before writing to the destination vector</p>



<a name="176549722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549722">(Sep 25 2019 at 09:56)</a>:</h4>
<p>it essentially doesn't matter where you move the complexity to</p>



<a name="176549743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549743">(Sep 25 2019 at 09:56)</a>:</h4>
<p>well the complexity now gets duplicated to all simd ops, because now they have to handle it again at that level</p>



<a name="176549810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549810">(Sep 25 2019 at 09:57)</a>:</h4>
<p>in all other interpreters I know, you just have one variant per operation, and a binary_op function that handles all binary operations</p>



<a name="176549819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549819">(Sep 25 2019 at 09:57)</a>:</h4>
<p>simd does overflowing ops?</p>



<a name="176549827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549827">(Sep 25 2019 at 09:57)</a>:</h4>
<p>it does saturating, wrapping</p>



<a name="176549837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549837">(Sep 25 2019 at 09:57)</a>:</h4>
<p>it also does comparisons, etc.</p>



<a name="176549886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549886">(Sep 25 2019 at 09:58)</a>:</h4>
<p>oh... I've never seen those</p>



<a name="176549899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549899">(Sep 25 2019 at 09:58)</a>:</h4>
<p>simd_saturating_add I think</p>



<a name="176549900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549900">(Sep 25 2019 at 09:58)</a>:</h4>
<p><a href="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51" target="_blank" title="https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51">https://github.com/rust-lang-nursery/packed_simd/blob/master/src/codegen/llvm.rs#L51</a> has only nonwrapping ones</p>



<a name="176549917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549917">(Sep 25 2019 at 09:58)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/search?q=simd_saturating_add&amp;unscoped_q=simd_saturating_add" target="_blank" title="https://github.com/rust-lang/rust/search?q=simd_saturating_add&amp;unscoped_q=simd_saturating_add">https://github.com/rust-lang/rust/search?q=simd_saturating_add&amp;unscoped_q=simd_saturating_add</a></p>



<a name="176549932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549932">(Sep 25 2019 at 09:59)</a>:</h4>
<p>either way, even if its just for Add vs Eq</p>



<a name="176549953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176549953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176549953">(Sep 25 2019 at 09:59)</a>:</h4>
<p>I need two different branches for the two different kinds of Ops :/</p>



<a name="176550054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550054">(Sep 25 2019 at 10:00)</a>:</h4>
<p>looking at codegen, you have the same problem there</p>



<a name="176550059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550059">(Sep 25 2019 at 10:00)</a>:</h4>
<p>I'm not sure how to avoid it</p>



<a name="176550074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550074">(Sep 25 2019 at 10:01)</a>:</h4>
<p>you can always add more wrapper functions ;)</p>



<a name="176550105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550105">(Sep 25 2019 at 10:01)</a>:</h4>
<p>if you manage to share the wrappers with regular wrapping/checked/... math, all the better</p>



<a name="176550161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550161">(Sep 25 2019 at 10:02)</a>:</h4>
<p>the codegen for the SIMD instructions is completely different than for the scalar instructions</p>



<a name="176550170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550170">(Sep 25 2019 at 10:02)</a>:</h4>
<p>for an interpreter, the execution of a SIMD instruction is just "loop over the elements and execute the scalar operation"</p>



<a name="176550190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550190">(Sep 25 2019 at 10:03)</a>:</h4>
<p>right, and you can just create a function that takes a closure, does the iteration, call the closure on each element</p>



<a name="176550198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550198">(Sep 25 2019 at 10:03)</a>:</h4>
<p>no, I can't</p>



<a name="176550201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550201">(Sep 25 2019 at 10:03)</a>:</h4>
<p>oh?</p>



<a name="176550205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550205">(Sep 25 2019 at 10:03)</a>:</h4>
<p>I want to write this code to cover all the arithmetic, bitwise, comparison, etc. binary operations:</p>



<a name="176550422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550422">(Sep 25 2019 at 10:06)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="n">v</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">is_simd_binop</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="kd">let</span><span class="w"> </span><span class="n">binop</span>: <span class="nc">mir</span>::<span class="n">BinOp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">simd_to_binop</span><span class="p">(</span><span class="n">v</span><span class="p">);</span><span class="w"></span>
<span class="w">   </span><span class="kd">let</span><span class="w"> </span><span class="n">len</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">simd_len</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span><span class="w"></span>
<span class="w">   </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="mi">0</span><span class="p">..</span><span class="n">len</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">binary_op</span><span class="p">(</span><span class="n">binop</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">operand_field</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="o">?</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">operand_field</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="o">?</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">write_immediate</span><span class="p">(</span><span class="n">result</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">operand_field</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="p">)</span><span class="o">?</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">   </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="176550545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550545">(Sep 25 2019 at 10:08)</a>:</h4>
<p>but I can't, because I need to duplicate the logic of the saturatin, wrapping, checked, etc. intrinsics in here</p>



<a name="176550557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550557">(Sep 25 2019 at 10:08)</a>:</h4>
<p>because the binop for all of them is just <code>Add</code></p>



<a name="176550569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550569">(Sep 25 2019 at 10:09)</a>:</h4>
<p>These are, however, different binary operations</p>



<a name="176550591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550591">(Sep 25 2019 at 10:09)</a>:</h4>
<p>if we were to have <code>mir::BinOp::CheckedAdd</code>, <code>WrappingAdd</code>, <code>SaturatingAdd</code>, <code>UncheckedAdd</code>, etc. instead</p>



<a name="176550609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550609">(Sep 25 2019 at 10:09)</a>:</h4>
<p>then at least at this level it would be super simple to just fall back to scalar code</p>



<a name="176550668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550668">(Sep 25 2019 at 10:10)</a>:</h4>
<p>that would mean that <code>binary_op</code> would need to match on these, and dispatch on them, and that wherever <code>SaturatingAdd</code> is implemented, that code might want to execute a <code>BinOp::CheckedAdd</code> internally</p>



<a name="176550715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176550715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176550715">(Sep 25 2019 at 10:11)</a>:</h4>
<p>I mean, having to match and convert <code>Add</code> to <code>(Add, true, false)</code> or whatever to indicate wrapping, checked, etc. semantics is weird</p>



<a name="176552030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176552030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176552030">(Sep 25 2019 at 10:35)</a>:</h4>
<p>so doing this would require <del>basic</del> fundamental changes to MIR, cc <span class="user-mention" data-user-id="119009">@eddyb</span></p>



<a name="176554376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176554376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176554376">(Sep 25 2019 at 11:18)</a>:</h4>
<p>so having look into that a bit more, I think the <code>mir::BinOp</code> only are intended to match the builtin <code>+</code> binary operators</p>



<a name="176554380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176554380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176554380">(Sep 25 2019 at 11:18)</a>:</h4>
<p>maybe we could have a different <code>BinOp</code> enum in the interpreter for the binary operations</p>



<a name="176554647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176554647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176554647">(Sep 25 2019 at 11:24)</a>:</h4>
<p>I still don't see why we would need that. You can create your own <code>binary_op</code> function that also takes an <code>enum OpKind { Checked, Wrapping, Saturating, Unchecked }</code> and dispatches the logic depending on that</p>



<a name="176554668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176554668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176554668">(Sep 25 2019 at 11:24)</a>:</h4>
<p>then <code>simd_to_binop</code> can return two enums</p>



<a name="176554732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176554732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176554732">(Sep 25 2019 at 11:25)</a>:</h4>
<p>as I said before, I don't think this needs deeper changes, you can just add more wrappers that give you the API you want</p>



<a name="176555327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555327">(Sep 25 2019 at 11:34)</a>:</h4>
<p>so now that i'm doing the asserts</p>



<a name="176555349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555349">(Sep 25 2019 at 11:34)</a>:</h4>
<p>how do I check that the compiler ices properly ?</p>



<a name="176555379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555379">(Sep 25 2019 at 11:35)</a>:</h4>
<p>the expected error is now 101</p>



<a name="176555383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555383">(Sep 25 2019 at 11:35)</a>:</h4>
<p>and not just 1</p>



<a name="176555390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555390">(Sep 25 2019 at 11:35)</a>:</h4>
<p>I also need one test per failure</p>



<a name="176555393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555393">(Sep 25 2019 at 11:35)</a>:</h4>
<p>:/</p>



<a name="176555913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176555913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176555913">(Sep 25 2019 at 11:43)</a>:</h4>
<blockquote>
<p>as I said before, I don't think this needs deeper changes, you can just add more wrappers that give you the API you want</p>
</blockquote>
<p>So... I should add a method to <code>operator.rs</code> that's called from <code>intrinsics.rs</code> and dispatches back to <code>intrinsics.rs</code> when necessary ?</p>



<a name="176556015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176556015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176556015">(Sep 25 2019 at 11:45)</a>:</h4>
<p>Like, for example, the binary saturating add simd operation would call the simd intrinsic for that, which would call this generic method, which would dispatch back to the scalar saturating intrinsics, which then call the normal add operations in <code>operators.rs</code></p>



<a name="176556019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176556019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176556019">(Sep 25 2019 at 11:45)</a>:</h4>
<p>I suppose I could do that</p>



<a name="176557281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176557281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176557281">(Sep 25 2019 at 12:04)</a>:</h4>
<blockquote>
<p>how do I check that the compiler ices properly ?</p>
</blockquote>
<p>you don't need to do that</p>



<a name="176557661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176557661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176557661">(Sep 25 2019 at 12:10)</a>:</h4>
<p>the PR currently does that, should I remove it ?</p>



<a name="176558871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176558871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176558871">(Sep 25 2019 at 12:29)</a>:</h4>
<p>yea, there's so many ways to ICE the compiler with unstable things and especially intrinsics, there's no point to it</p>



<a name="176558888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176558888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176558888">(Sep 25 2019 at 12:29)</a>:</h4>
<p>it won't actuall help us catch bugs if we test for it</p>



<a name="176559061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176559061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176559061">(Sep 25 2019 at 12:31)</a>:</h4>
<p>otherwise the PR lgtm now</p>



<a name="176559112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176559112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176559112">(Sep 25 2019 at 12:32)</a>:</h4>
<p>I'm removing the fail tests, will update it soon</p>



<a name="176559155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/simd%20in%20const%20fn%20%2364738/near/176559155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/simd.20in.20const.20fn.20.2364738.html#176559155">(Sep 25 2019 at 12:33)</a>:</h4>
<p>Done</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>